<!doctype html><html lang="en">
 <head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <title>Sensor Use Cases</title>
  <meta content="NOTE" name="w3c-status">
  <link href="https://www.w3.org/StyleSheets/TR/2016/W3C-NOTE" rel="stylesheet">
  <link href="https://www.w3.org/2008/site/images/favicon.ico" rel="icon">
  <link href="http://www.w3.org/TR/generic-sensor-usecases/" rel="canonical">
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
   regarding paragraph and lists. */
[data-md] > :first-child {
    margin-top: 0;
}
[data-md] > :last-child {
    margin-bottom: 0;
}</style>
<style>/* style-selflinks */

.heading, .issue, .note, .example, li, dt {
    position: relative;
}
a.self-link {
    position: absolute;
    top: 0;
    left: calc(-1 * (3.5rem - 26px));
    width: calc(3.5rem - 26px);
    height: 2em;
    text-align: center;
    border: none;
    transition: opacity .2s;
    opacity: .5;
}
a.self-link:hover {
    opacity: 1;
}
.heading > a.self-link {
    font-size: 83%;
}
li > a.self-link {
    left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
    top: auto;
    left: auto;
    opacity: 0;
    width: 1.5em;
    height: 1.5em;
    background: gray;
    color: white;
    font-style: normal;
    transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
    opacity: 1;
}
dfn > a.self-link:hover {
    color: black;
}

a.self-link::before            { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before      { content: "#"; }</style>
<style>/* style-counters */

body {
    counter-reset: example figure issue;
}
.issue {
    counter-increment: issue;
}
.issue:not(.no-marker)::before {
    content: "Issue " counter(issue);
}

.example {
    counter-increment: example;
}
.example:not(.no-marker)::before {
    content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
    content: "Invalid Example" counter(example);
}

figcaption {
    counter-increment: figure;
}
figcaption:not(.no-marker)::before {
    content: "Figure " counter(figure) " ";
}</style>
<style>/* style-autolinks */

.css.css, .property.property, .descriptor.descriptor {
    color: #005a9c;
    font-size: inherit;
    font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
    content: "‘";
}
.css::after, .property::after, .descriptor::after {
    content: "’";
}
.property, .descriptor {
    /* Don't wrap property and descriptor names */
    white-space: nowrap;
}
.type { /* CSS value <type> */
    font-style: italic;
}
pre .property::before, pre .property::after {
    content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
    content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
    content: "’";
}

[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
    content: "";
}

[data-link-type=element],
[data-link-type=element-attr] {
    font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
    font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after  { content: ">" }

[data-link-type=biblio] {
    white-space: pre;
}</style>
<style>/* style-dfn-panel */

.dfn-panel {
    position: absolute;
    z-index: 35;
    height: auto;
    width: -webkit-fit-content;
    width: fit-content;
    max-width: 300px;
    max-height: 500px;
    overflow: auto;
    padding: 0.5em 0.75em;
    font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
    background: #DDDDDD;
    color: black;
    border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
    display: inline-block;
    position: fixed;
    left: .5em;
    bottom: 2em;
    margin: 0 auto;
    max-width: calc(100vw - 1.5em - .4em - .5em);
    max-height: 30vh;
}

.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-syntax-highlighting */

.highlight:not(.idl) { background: hsl(24, 20%, 95%); }
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
c-[a] { color: #990055 } /* Keyword.Declaration */
c-[b] { color: #990055 } /* Keyword.Type */
c-[c] { color: #708090 } /* Comment */
c-[d] { color: #708090 } /* Comment.Multiline */
c-[e] { color: #0077aa } /* Name.Attribute */
c-[f] { color: #669900 } /* Name.Tag */
c-[g] { color: #222222 } /* Name.Variable */
c-[k] { color: #990055 } /* Keyword */
c-[l] { color: #000000 } /* Literal */
c-[m] { color: #000000 } /* Literal.Number */
c-[n] { color: #0077aa } /* Name */
c-[o] { color: #999999 } /* Operator */
c-[p] { color: #999999 } /* Punctuation */
c-[s] { color: #a67f59 } /* Literal.String */
c-[t] { color: #a67f59 } /* Literal.String.Single */
c-[u] { color: #a67f59 } /* Literal.String.Double */
c-[cp] { color: #708090 } /* Comment.Preproc */
c-[c1] { color: #708090 } /* Comment.Single */
c-[cs] { color: #708090 } /* Comment.Special */
c-[kc] { color: #990055 } /* Keyword.Constant */
c-[kn] { color: #990055 } /* Keyword.Namespace */
c-[kp] { color: #990055 } /* Keyword.Pseudo */
c-[kr] { color: #990055 } /* Keyword.Reserved */
c-[ld] { color: #000000 } /* Literal.Date */
c-[nc] { color: #0077aa } /* Name.Class */
c-[no] { color: #0077aa } /* Name.Constant */
c-[nd] { color: #0077aa } /* Name.Decorator */
c-[ni] { color: #0077aa } /* Name.Entity */
c-[ne] { color: #0077aa } /* Name.Exception */
c-[nf] { color: #0077aa } /* Name.Function */
c-[nl] { color: #0077aa } /* Name.Label */
c-[nn] { color: #0077aa } /* Name.Namespace */
c-[py] { color: #0077aa } /* Name.Property */
c-[ow] { color: #999999 } /* Operator.Word */
c-[mb] { color: #000000 } /* Literal.Number.Bin */
c-[mf] { color: #000000 } /* Literal.Number.Float */
c-[mh] { color: #000000 } /* Literal.Number.Hex */
c-[mi] { color: #000000 } /* Literal.Number.Integer */
c-[mo] { color: #000000 } /* Literal.Number.Oct */
c-[sb] { color: #a67f59 } /* Literal.String.Backtick */
c-[sc] { color: #a67f59 } /* Literal.String.Char */
c-[sd] { color: #a67f59 } /* Literal.String.Doc */
c-[se] { color: #a67f59 } /* Literal.String.Escape */
c-[sh] { color: #a67f59 } /* Literal.String.Heredoc */
c-[si] { color: #a67f59 } /* Literal.String.Interpol */
c-[sx] { color: #a67f59 } /* Literal.String.Other */
c-[sr] { color: #a67f59 } /* Literal.String.Regex */
c-[ss] { color: #a67f59 } /* Literal.String.Symbol */
c-[vc] { color: #0077aa } /* Name.Variable.Class */
c-[vg] { color: #0077aa } /* Name.Variable.Global */
c-[vi] { color: #0077aa } /* Name.Variable.Instance */
c-[il] { color: #000000 } /* Literal.Number.Integer.Long */
</style>
 <body class="h-entry">
  <div class="head">
   <p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
   <h1 class="p-name no-ref" id="title">Sensor Use Cases</h1>
   <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">W3C Note, <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
   <div data-fill-with="spec-metadata">
    <dl>
     <dt>This version:
     <dd><a class="u-url" href="https://www.w3.org/TR/1970/NOTE-generic-sensor-usecases-19700101/">https://www.w3.org/TR/1970/NOTE-generic-sensor-usecases-19700101/</a>
     <dt>Latest published version:
     <dd><a href="http://www.w3.org/TR/generic-sensor-usecases/">http://www.w3.org/TR/generic-sensor-usecases/</a>
     <dt>Editor's Draft:
     <dd><a href="https://w3c.github.io/sensors/usecases">https://w3c.github.io/sensors/usecases</a>
     <dt>Version History:
     <dd><a href="https://github.com/w3c/sensors/commits/gh-pages/index.bs">https://github.com/w3c/sensors/commits/gh-pages/index.bs</a>
     <dt>Feedback:
     <dd><span><a href="mailto:public-device-apis@w3.org?subject=%5Bgeneric-sensor-usecases%5D%20YOUR%20TOPIC%20HERE">public-device-apis@w3.org</a> with subject line “<kbd>[generic-sensor-usecases] <i data-lt>… message topic …</i></kbd>” (<a href="https://lists.w3.org/Archives/Public/public-device-apis/" rel="discussion">archives</a>)</span>
     <dt class="editor">Editors:
     <dd class="editor p-author h-card vcard" data-editor-id="50572"><span class="p-name fn">Rick Waldron</span> (<span class="p-org org">Bocoup, formerly on behalf of JS Foundation</span>)
     <dd class="editor p-author h-card vcard" data-editor-id="78325"><a class="p-name fn u-url url" href="https://intel.com/">Mikhail Pozdnyakov</a> (<span class="p-org org">Intel Corporation</span>)
     <dd class="editor p-author h-card vcard" data-editor-id="78335"><a class="p-name fn u-url url" href="https://intel.com/">Alexander Shalamov</a> (<span class="p-org org">Intel Corporation</span>)
     <dt class="editor">Former Editor:
     <dd class="editor p-author h-card vcard" data-editor-id="60809"><a class="p-name fn u-url url" href="http://tobie.me">Tobie Langel</a> (<span class="p-org org">Codespeaks, formerly on behalf of Intel Corporation</span>) <a class="u-email email" href="mailto:tobie@codespeaks.com">tobie@codespeaks.com</a>
     <dt>Bug Reports:
     <dd><a href="https://www.github.com/w3c/sensors/issues/new">via the w3c/sensors repository on GitHub</a>
     <dt>Issue Tracking:
     <dd><a href="https://github.com/w3c/sensors/milestones/Level%201">Level 1 Issues</a>
    </dl>
   </div>
   <div data-fill-with="warning"></div>
   <p class="copyright" data-fill-with="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 1970 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="https://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document" rel="license">permissive document license</a> rules apply. </p>
   <hr title="Separator for header">
  </div>
  <div class="p-summary" data-fill-with="abstract">
   <h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
   <p>This document lists use cases for sensor data exposed to the Open Web Platform along with code examples of how Web developers ("authors" in spec speech) would listen to sensor data and use it within their application-level code.</p>
  </div>
  <h2 class="no-num no-toc no-ref heading settled" id="sotd"><span class="content">Status of this document</span></h2>
  <div data-fill-with="status">
   <p></p>
  </div>
  <div data-fill-with="at-risk"></div>
  <nav data-fill-with="table-of-contents" id="toc">
   <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
   <ol class="toc" role="directory">
    <li><a href="#intro"><span class="secno">1</span> <span class="content">Introduction</span></a>
    <li>
     <a href="#usecases-and-requirements"><span class="secno">2</span> <span class="content">Use Cases and requirements</span></a>
     <ol class="toc">
      <li><a href="#environmental-sensors"><span class="secno">2.1</span> <span class="content">Environmental sensors</span></a>
      <li><a href="#inertial-sensors"><span class="secno">2.2</span> <span class="content">Inertial sensors</span></a>
      <li><a href="#fusion-sensors"><span class="secno">2.3</span> <span class="content">Fusion sensors</span></a>
      <li><a href="#custom-fusion-sensors"><span class="secno">2.4</span> <span class="content">Creating custom fusion sensors</span></a>
      <li><a href="#trigger-sensors"><span class="secno">2.5</span> <span class="content">Trigger sensors</span></a>
     </ol>
    <li>
     <a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
     <ol class="toc">
      <li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
     </ol>
    <li>
     <a href="#references"><span class="secno"></span> <span class="content">References</span></a>
     <ol class="toc">
      <li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
     </ol>
   </ol>
  </nav>
  <main>
   <h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content">Introduction</span><a class="self-link" href="#intro"></a></h2>
   <p>The Generic Sensor API provides generic interfaces for accessing sensors. The purpose of this
document is to collect use cases, requirements, references to applicable documents and concrete
sensor specifications in order to provide input for Generic Sensor API improvements.</p>
   <h2 class="heading settled" data-level="2" id="usecases-and-requirements"><span class="secno">2. </span><span class="content">Use Cases and requirements</span><a class="self-link" href="#usecases-and-requirements"></a></h2>
   <p>The use cases and requirements for the sensors differ from one application to another. In this
section, sensors are grouped into categories that represent particular set of common use cases.</p>
   <h3 class="heading settled" data-level="2.1" id="environmental-sensors"><span class="secno">2.1. </span><span class="content">Environmental sensors</span><a class="self-link" href="#environmental-sensors"></a></h3>
   <p>This group of sensors measure physical properties of the environment they are in. For example,
sensors that measure barometric air pressure, humidity, ambient light, ambient air temperature,
etc., belong to this group.</p>
   <p>Environmental sensors might be used in applications like: home automation, accessibility, personal
weather forecast, sport and fitness monitoring. Additional use cases and requirements can be found
from corresponding environmental sensors that are based on Generic Sensor API:</p>
   <ul>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/ambient-light#usecases-requirements" id="ref-for-usecases-requirements">Ambient light sensor</a></p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/proximity#proximity-sensor-interface" id="ref-for-proximity-sensor-interface">Proximity sensor</a></p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/magnetometer#usecases-and-requirements" id="ref-for-usecases-and-requirements"> Magnetometer</a></p>
   </ul>
   <h3 class="heading settled" data-level="2.2" id="inertial-sensors"><span class="secno">2.2. </span><span class="content">Inertial sensors</span><a class="self-link" href="#inertial-sensors"></a></h3>
   <p>This group of sensors is based on inertia and relevant measuring concepts. Usually, inertial
sensors are part of IMU (Inertial Measurements Unit) that measure <a data-link-type="dfn" href="https://w3c.github.io/accelerometer#acceleration" id="ref-for-acceleration">acceleration</a> using <a data-link-type="dfn" href="https://w3c.github.io/accelerometer#accelerometer-interface" id="ref-for-accelerometer-interface">accelerometer</a> and <a data-link-type="dfn" href="https://w3c.github.io/gyroscope#angular-velocity" id="ref-for-angular-velocity">rotational rate</a> using <a data-link-type="dfn" href="https://w3c.github.io/gyroscope#gyroscope-interface" id="ref-for-gyroscope-interface">gyroscope</a>. <a data-link-type="dfn" href="https://w3c.github.io/magnetometer#magnetometer-interface" id="ref-for-magnetometer-interface">Magnetometer</a> might be part of IMU and
provide data to calculate heading reference and/or <a data-link-type="dfn" href="https://w3c.github.io/gyroscope#gyroscope-interface" id="ref-for-gyroscope-interface①">gyroscope</a> drift correction.</p>
   <p>Inertial sensors enable various use cases, such as: virtual and augmented reality, immersive gaming,
activity recognition, sport and fitness monitoring, 3D scanning, indoor navigation and mapping.
The <a data-link-type="dfn" href="https://w3c.github.io/motion-sensors#usecases-and-requirements" id="ref-for-usecases-and-requirements①">motion sensors explainer</a> has extensive list of use cases and references to applicable
scientific papers.</p>
   <p>The following inertial sensors are based on Generic Sensor API:</p>
   <ul>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/accelerometer#accelerometer-interface" id="ref-for-accelerometer-interface①">Accelerometer</a></p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/gyroscope#gyroscope-interface" id="ref-for-gyroscope-interface②">Gyroscope</a></p>
   </ul>
   <h3 class="heading settled" data-level="2.3" id="fusion-sensors"><span class="secno">2.3. </span><span class="content">Fusion sensors</span><a class="self-link" href="#fusion-sensors"></a></h3>
   <p>This group of sensors provide measurements that are 'fused together' by fusion algorithm. The
fusion algorithms might require data from one or multiple sources. For example, the data
provided by the relative orientation sensor can be fused from <a data-link-type="dfn" href="https://w3c.github.io/accelerometer#accelerometer-interface" id="ref-for-accelerometer-interface②">accelerometer</a> or be a combination
of <a data-link-type="dfn" href="https://w3c.github.io/accelerometer#accelerometer-interface" id="ref-for-accelerometer-interface③">accelerometer</a> and <a data-link-type="dfn" href="https://w3c.github.io/gyroscope#gyroscope-interface" id="ref-for-gyroscope-interface③">gyroscope</a> data. The most common use cases for fusion sensors can be found in
the <a data-link-type="dfn" href="https://w3c.github.io/motion-sensors#usecases-and-requirements" id="ref-for-usecases-and-requirements②">motion sensors explainer</a> document.</p>
   <p>The following fusion sensors are based on Generic Sensor API:</p>
   <ul>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/orientation-sensor#absoluteorientationsensor-interface" id="ref-for-absoluteorientationsensor-interface">Absolute orientation sensor</a></p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/orientation-sensor#relativeorientationsensor-interface" id="ref-for-relativeorientationsensor-interface">Relative orientation sensor</a></p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/accelerometer#linearaccelerationsensor-interface" id="ref-for-linearaccelerationsensor-interface">Linear acceleration sensor</a></p>
    <li data-md>
     <p><a data-link-type="dfn" href="https://w3c.github.io/accelerometer#gravitysensor-interface" id="ref-for-gravitysensor-interface">Gravity sensor</a></p>
   </ul>
   <p class="note" role="note"><span>Note:</span> The <a data-link-type="dfn" href="https://w3c.github.io/magnetometer#magnetometer-interface" id="ref-for-magnetometer-interface①">Magnetometer</a> is often used to improve integrity of the data provided by <a data-link-type="dfn" href="https://w3c.github.io/accelerometer#accelerometer-interface" id="ref-for-accelerometer-interface④">accelerometer</a> and/or <a data-link-type="dfn" href="https://w3c.github.io/gyroscope#gyroscope-interface" id="ref-for-gyroscope-interface④">gyroscope</a>, as well as for establishing frame of reference based on
Earth’s coordinate system.</p>
   <h3 class="heading settled" data-level="2.4" id="custom-fusion-sensors"><span class="secno">2.4. </span><span class="content">Creating custom fusion sensors</span><a class="self-link" href="#custom-fusion-sensors"></a></h3>
   <p>The web applications might require data that is not provided by the UA. Generic Sensor API allows
implementation of custom fusion sensors that may fulfill special use cases.</p>
   <p class="issue" id="issue-f96e1b22"><a class="self-link" href="#issue-f96e1b22"></a> We might need to think about opening this as an improvement for Generic Sensor API.
Interface that will take fusion algorithm and as a result, provide new sensor property and/or
modify <code>onreading</code> behavior. This will enable implementation of various sensors, like:
SimpleOrientation, FreeFall, Pedometer, Compass  or simple <a href="#trigger-sensors"> trigger sensors</a>.</p>
   <p>In cases when web application requires additional functionality from the concrete sensor, extension
of the base sensor interface might be the simplest solution.</p>
   <div class="example" id="example-92e5182d">
    <a class="self-link" href="#example-92e5182d"></a> In this example, we create a simple linear free fall detection sensor. 
<pre class="highlight"><c- kr>class</c-> FreeFallSensor <c- kr>extends</c-> Accelerometer <c- p>{</c->
    set onreading<c- p>(</c->func<c- p>)</c-> <c- p>{</c->
        <c- kr>super</c-><c- p>.</c->onreading <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c->
            <c- a>let</c-> isFalling <c- o>=</c-> Math<c- p>.</c->hypot<c- p>(</c-><c- kr>super</c-><c- p>.</c->x<c- p>,</c-> <c- kr>super</c-><c- p>.</c->y<c- p>,</c-> <c- kr>super</c-><c- p>.</c->z<c- p>)</c-> <c- o>&lt;</c-> <c- mf>0.5</c-><c- p>;</c->
            <c- k>if</c-> <c- p>(</c-><c- k>this</c-><c- p>.</c->inFreeFall_ <c- o>!=</c-> isFalling<c- p>)</c-> <c- p>{</c->
                <c- k>this</c-><c- p>.</c->inFreeFall_ <c- o>=</c->  isFalling<c- p>;</c->
                func<c- p>();</c->
            <c- p>}</c->
        <c- p>}</c->
    <c- p>}</c->

    get inFreeFall<c- p>()</c-> <c- p>{</c->
        <c- k>return</c-> <c- k>this</c-><c- p>.</c->inFreeFall_<c- p>;</c->
    <c- p>}</c->
<c- p>}</c->
</pre>
   </div>
   <p>When the web application requires measurements that are fused from multiple sensor sources,
simple aggregation pattern may be used.</p>
   <div class="example" id="example-8caf49fa">
    <a class="self-link" href="#example-8caf49fa"></a> In this simplified example, we define <code>FusionSensor</code> class that aggregates multiple
    sources and provides fused data. 
<pre class="highlight"><c- kr>class</c-> FusionSensor <c- p>{</c->
    constructor<c- p>(</c->sensors<c- p>,</c-> algorithm<c- p>)</c-> <c- p>{</c->
        <c- k>this</c-><c- p>.</c->sensors_ <c- o>=</c-> sensors<c- p>;</c->
        <c- k>this</c-><c- p>.</c->algorithm_ <c- o>=</c-> algorithm<c- p>.</c->bind<c- p>(</c-><c- k>this</c-><c- p>);</c->
    <c- p>}</c->

    start<c- p>()</c-> <c- p>{</c->
        <c- k>this</c-><c- p>.</c->sensors_<c- p>.</c->map<c- p>(</c->sensor <c- p>=></c-> sensor<c- p>.</c->start<c- p>());</c->
    <c- p>}</c->

    stop<c- p>()</c->  <c- p>{</c->
        <c- k>this</c-><c- p>.</c->sensors_<c- p>.</c->map<c- p>(</c->sensor <c- p>=></c-> sensor<c- p>.</c->stop<c- p>());</c->
    <c- p>}</c->

    set onreading<c- p>(</c->func<c- p>)</c-> <c- p>{</c->
        <c- k>this</c-><c- p>.</c->sensors_<c- p>.</c->map<c- p>(</c->sensor <c- p>=></c-> <c- p>{</c->
            sensor<c- p>.</c->onreading <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c->
                <c- k>this</c-><c- p>.</c->fusedReading_ <c- o>=</c-> <c- k>this</c-><c- p>.</c->algorithm_<c- p>(</c->sensor<c- p>,</c-> <c- k>this</c-><c- p>.</c->sensors_<c- p>);</c->
                func<c- p>();</c->
            <c- p>}</c->
        <c- p>});</c->
    <c- p>}</c->

    get fusedReading<c- p>()</c-> <c- p>{</c->
        <c- k>return</c-> <c- k>this</c-><c- p>.</c->fusedReading_<c- p>;</c->
    <c- p>}</c->
<c- p>}</c->

<c- c1>// Stateful algorithm that finds brightest spot during calibration phase and uses</c->
<c- c1>// it as a fixed frame of reference to calculate relative orientation from brightest</c->
<c- c1>// light source.</c->
<c- a>let</c-> custom_algo <c- o>=</c-> <c- p>(</c->changed_source<c- p>,</c-> all_sources<c- p>)</c-> <c- p>=></c-> <c- p>{</c-> <c- k>return</c-> <c- k>new</c-> DOMMatrix<c- p>();</c-> <c- p>}</c->
<c- a>let</c-> source_sensors <c- o>=</c-> <c- p>[</c-><c- k>new</c-> Accelerometer<c- p>(),</c-> <c- k>new</c-> Gyroscope<c- p>(),</c-> <c- k>new</c-> AmbientLightSensor<c- p>()];</c->
<c- a>let</c-> sensor <c- o>=</c-> <c- k>new</c-> FusionSensor<c- p>(</c->source_sensors<c- p>,</c-> custom_algo<c- p>);</c->
sensor<c- p>.</c->onreading <c- o>=</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c-> console<c- p>.</c->log<c- p>(</c->JSON<c- p>.</c->stringify<c- p>(</c->sensor<c- p>.</c->fusedReading<c- p>));</c-> <c- p>}</c->
sensor<c- p>.</c->start<c- p>();</c->
</pre>
   </div>
   <h3 class="heading settled" data-level="2.5" id="trigger-sensors"><span class="secno">2.5. </span><span class="content">Trigger sensors</span><a class="self-link" href="#trigger-sensors"></a></h3>
   <p class="issue" id="issue-4af7337d"><a class="self-link" href="#issue-4af7337d"></a> This group of sensors may not need frequency. The HW will just fire interrupt to
signal about the change. If trigger sensor functionality is provided by e.g., <a data-link-type="dfn" href="https://w3c.github.io/accelerometer#accelerometer-interface" id="ref-for-accelerometer-interface⑤">accelerometer</a>,
sensor would be operating in special low-power mode.</p>
   <p>For the purpose of this document, trigger sensors group is characterised by the simplicity
of the hardware, limited sensor configuration capabilities, special mode of operation or
notification mechanism for the new sensor readings. For example, reed switch or hall effect sensors
that will trigger hardware interrupt and provide one bit reading data (on / off).</p>
   <p>The following list of sensors might be a good example of trigger sensors:</p>
   <ul>
    <li data-md>
     <p>Reed switch and hall effect sensors</p>
    <li data-md>
     <p>Significant motion, no motion, tap, flat, free fall, low-g and high-g sensors</p>
    <li data-md>
     <p>Laser or infrared switch sensors</p>
   </ul>
  </main>
<script src="https://www.w3.org/scripts/TR/2016/fixup.js"></script>
  <h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
  <aside class="dfn-panel" data-for="term-for-acceleration">
   <a href="https://w3c.github.io/accelerometer#acceleration">https://w3c.github.io/accelerometer#acceleration</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-acceleration">2.2. Inertial sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-accelerometer-interface">
   <a href="https://w3c.github.io/accelerometer#accelerometer-interface">https://w3c.github.io/accelerometer#accelerometer-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-accelerometer-interface">2.2. Inertial sensors</a> <a href="#ref-for-accelerometer-interface①">(2)</a>
    <li><a href="#ref-for-accelerometer-interface②">2.3. Fusion sensors</a> <a href="#ref-for-accelerometer-interface③">(2)</a> <a href="#ref-for-accelerometer-interface④">(3)</a>
    <li><a href="#ref-for-accelerometer-interface⑤">2.5. Trigger sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-gravitysensor-interface">
   <a href="https://w3c.github.io/accelerometer#gravitysensor-interface">https://w3c.github.io/accelerometer#gravitysensor-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-gravitysensor-interface">2.3. Fusion sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-linearaccelerationsensor-interface">
   <a href="https://w3c.github.io/accelerometer#linearaccelerationsensor-interface">https://w3c.github.io/accelerometer#linearaccelerationsensor-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-linearaccelerationsensor-interface">2.3. Fusion sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-usecases-requirements">
   <a href="https://w3c.github.io/ambient-light#usecases-requirements">https://w3c.github.io/ambient-light#usecases-requirements</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-usecases-requirements">2.1. Environmental sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-gyroscope-interface">
   <a href="https://w3c.github.io/gyroscope#gyroscope-interface">https://w3c.github.io/gyroscope#gyroscope-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-gyroscope-interface">2.2. Inertial sensors</a> <a href="#ref-for-gyroscope-interface①">(2)</a> <a href="#ref-for-gyroscope-interface②">(3)</a>
    <li><a href="#ref-for-gyroscope-interface③">2.3. Fusion sensors</a> <a href="#ref-for-gyroscope-interface④">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-angular-velocity">
   <a href="https://w3c.github.io/gyroscope#angular-velocity">https://w3c.github.io/gyroscope#angular-velocity</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-angular-velocity">2.2. Inertial sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-magnetometer-interface">
   <a href="https://w3c.github.io/magnetometer#magnetometer-interface">https://w3c.github.io/magnetometer#magnetometer-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-magnetometer-interface">2.2. Inertial sensors</a>
    <li><a href="#ref-for-magnetometer-interface①">2.3. Fusion sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-usecases-and-requirements">
   <a href="https://w3c.github.io/magnetometer#usecases-and-requirements">https://w3c.github.io/magnetometer#usecases-and-requirements</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-usecases-and-requirements">2.1. Environmental sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-usecases-and-requirements">
   <a href="https://w3c.github.io/motion-sensors#usecases-and-requirements">https://w3c.github.io/motion-sensors#usecases-and-requirements</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-usecases-and-requirements①">2.2. Inertial sensors</a>
    <li><a href="#ref-for-usecases-and-requirements②">2.3. Fusion sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-absoluteorientationsensor-interface">
   <a href="https://w3c.github.io/orientation-sensor#absoluteorientationsensor-interface">https://w3c.github.io/orientation-sensor#absoluteorientationsensor-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-absoluteorientationsensor-interface">2.3. Fusion sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-relativeorientationsensor-interface">
   <a href="https://w3c.github.io/orientation-sensor#relativeorientationsensor-interface">https://w3c.github.io/orientation-sensor#relativeorientationsensor-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-relativeorientationsensor-interface">2.3. Fusion sensors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-proximity-sensor-interface">
   <a href="https://w3c.github.io/proximity#proximity-sensor-interface">https://w3c.github.io/proximity#proximity-sensor-interface</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-proximity-sensor-interface">2.1. Environmental sensors</a>
   </ul>
  </aside>
  <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
  <ul class="index">
   <li>
    <a data-link-type="biblio">[accelerometer]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-acceleration" style="color:initial">acceleration</span>
     <li><span class="dfn-paneled" id="term-for-accelerometer-interface" style="color:initial">accelerometer</span>
     <li><span class="dfn-paneled" id="term-for-gravitysensor-interface" style="color:initial">gravity sensor</span>
     <li><span class="dfn-paneled" id="term-for-linearaccelerationsensor-interface" style="color:initial">linear acceleration sensor</span>
    </ul>
   <li>
    <a data-link-type="biblio">[ambient-light]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-usecases-requirements" style="color:initial">ambient light sensor</span>
    </ul>
   <li>
    <a data-link-type="biblio">[gyroscope]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-gyroscope-interface" style="color:initial">gyroscope</span>
     <li><span class="dfn-paneled" id="term-for-angular-velocity" style="color:initial">rotational rate</span>
    </ul>
   <li>
    <a data-link-type="biblio">[magnetometer]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-magnetometer-interface" style="color:initial">magnetometer</span>
     <li><span class="dfn-paneled" id="term-for-usecases-and-requirements" style="color:initial">magnetometer use cases</span>
    </ul>
   <li>
    <a data-link-type="biblio">[motion-sensors]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-usecases-and-requirements①" style="color:initial">motion sensors explainer</span>
    </ul>
   <li>
    <a data-link-type="biblio">[orientation-sensor]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-absoluteorientationsensor-interface" style="color:initial">absolute orientation sensor</span>
     <li><span class="dfn-paneled" id="term-for-relativeorientationsensor-interface" style="color:initial">relative orientation sensor</span>
    </ul>
   <li>
    <a data-link-type="biblio">[proximity]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-proximity-sensor-interface" style="color:initial">proximity sensor</span>
    </ul>
  </ul>
  <h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
  <h3 class="no-num no-ref heading settled" id="normative"><span class="content">Normative References</span><a class="self-link" href="#normative"></a></h3>
  <dl>
   <dt id="biblio-accelerometer">[ACCELEROMETER]
   <dd>Anssi Kostiainen. <a href="https://www.w3.org/TR/accelerometer/">Accelerometer</a>. 7 March 2019. WD. URL: <a href="https://www.w3.org/TR/accelerometer/">https://www.w3.org/TR/accelerometer/</a>
   <dt id="biblio-ambient-light">[AMBIENT-LIGHT]
   <dd>Anssi Kostiainen. <a href="https://www.w3.org/TR/ambient-light/">Ambient Light Sensor</a>. 7 March 2019. WD. URL: <a href="https://www.w3.org/TR/ambient-light/">https://www.w3.org/TR/ambient-light/</a>
   <dt id="biblio-gyroscope">[GYROSCOPE]
   <dd>Anssi Kostiainen. <a href="https://www.w3.org/TR/gyroscope/">Gyroscope</a>. 7 March 2019. WD. URL: <a href="https://www.w3.org/TR/gyroscope/">https://www.w3.org/TR/gyroscope/</a>
   <dt id="biblio-magnetometer">[MAGNETOMETER]
   <dd>Anssi Kostiainen; Rijubrata Bhaumik. <a href="https://www.w3.org/TR/magnetometer/">Magnetometer</a>. 7 March 2019. WD. URL: <a href="https://www.w3.org/TR/magnetometer/">https://www.w3.org/TR/magnetometer/</a>
   <dt id="biblio-motion-sensors">[MOTION-SENSORS]
   <dd>Kenneth Christiansen; Alexander Shalamov. <a href="https://www.w3.org/TR/motion-sensors/">Motion Sensors Explainer</a>. 30 August 2017. NOTE. URL: <a href="https://www.w3.org/TR/motion-sensors/">https://www.w3.org/TR/motion-sensors/</a>
   <dt id="biblio-orientation-sensor">[ORIENTATION-SENSOR]
   <dd>Kenneth Christiansen; Anssi Kostiainen. <a href="https://www.w3.org/TR/orientation-sensor/">Orientation Sensor</a>. 7 March 2019. WD. URL: <a href="https://www.w3.org/TR/orientation-sensor/">https://www.w3.org/TR/orientation-sensor/</a>
   <dt id="biblio-proximity">[PROXIMITY]
   <dd>Anssi Kostiainen; Rijubrata Bhaumik. <a href="https://www.w3.org/TR/proximity/">Proximity Sensor</a>. 5 March 2019. WD. URL: <a href="https://www.w3.org/TR/proximity/">https://www.w3.org/TR/proximity/</a>
  </dl>
<script>/* script-dfn-panel */

document.body.addEventListener("click", function(e) {
    var queryAll = function(sel) { return [].slice.call(document.querySelectorAll(sel)); }
    // Find the dfn element or panel, if any, that was clicked on.
    var el = e.target;
    var target;
    var hitALink = false;
    while(el.parentElement) {
        if(el.tagName == "A") {
            // Clicking on a link in a <dfn> shouldn't summon the panel
            hitALink = true;
        }
        if(el.classList.contains("dfn-paneled")) {
            target = "dfn";
            break;
        }
        if(el.classList.contains("dfn-panel")) {
            target = "dfn-panel";
            break;
        }
        el = el.parentElement;
    }
    if(target != "dfn-panel") {
        // Turn off any currently "on" or "activated" panels.
        queryAll(".dfn-panel.on, .dfn-panel.activated").forEach(function(el){
            el.classList.remove("on");
            el.classList.remove("activated");
        });
    }
    if(target == "dfn" && !hitALink) {
        // open the panel
        var dfnPanel = document.querySelector(".dfn-panel[data-for='" + el.id + "']");
        if(dfnPanel) {
            dfnPanel.classList.add("on");
            var rect = el.getBoundingClientRect();
            dfnPanel.style.left = window.scrollX + rect.right + 5 + "px";
            dfnPanel.style.top = window.scrollY + rect.top + "px";
            var panelRect = dfnPanel.getBoundingClientRect();
            var panelWidth = panelRect.right - panelRect.left;
            if(panelRect.right > document.body.scrollWidth && (rect.left - (panelWidth + 5)) > 0) {
                // Reposition, because the panel is overflowing
                dfnPanel.style.left = window.scrollX + rect.left - (panelWidth + 5) + "px";
            }
        } else {
            console.log("Couldn't find .dfn-panel[data-for='" + el.id + "']");
        }
    } else if(target == "dfn-panel") {
        // Switch it to "activated" state, which pins it.
        el.classList.add("activated");
        el.style.left = null;
        el.style.top = null;
    }

});
</script>